/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "rtthread.h"
#include "GQueue.h"
/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
//主板本，子版本，修订版本
#define SOFTVER     "1.0.0"
#define CLIP(x,n,m)     (x) = (x) > (m) ? (m) : (x) < (n) ? (n) : (x)

/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define CTRL_5V_Pin GPIO_PIN_1
#define CTRL_5V_GPIO_Port GPIOB
#define PHY_RST_Pin GPIO_PIN_10
#define PHY_RST_GPIO_Port GPIOB
#define LED1_Pin GPIO_PIN_8
#define LED1_GPIO_Port GPIOD
#define LED2_Pin GPIO_PIN_9
#define LED2_GPIO_Port GPIOD
#define RS485_EN_Pin GPIO_PIN_8
#define RS485_EN_GPIO_Port GPIOC
#define VER_1_Pin GPIO_PIN_8
#define VER_1_GPIO_Port GPIOA
#define VER_2_Pin GPIO_PIN_9
#define VER_2_GPIO_Port GPIOA
#define VER_3_Pin GPIO_PIN_10
#define VER_3_GPIO_Port GPIOA

/* USER CODE BEGIN Private defines */
/* thread manage */

#define YM_BUFSIZE                  2048

#define DEFAULT_PRIORITY            8
#define DEFAULT_STACK_SIZE          2048
#define DEFAULT_TIME_SLICE          5

#define RYM_DOWN_PRIORITY           (DEFAULT_PRIORITY+1)
#define RYM_DOWN_STACK_SIZE         1024
#define RYM_DOWN_TIME_SLICE         5

#define RYM_UP_PRIORITY             (DEFAULT_PRIORITY+1)
#define RYM_UP_STACK_SIZE           1024
#define RYM_UP_TIME_SLICE           5

#define ETHERIF_PRIORITY            DEFAULT_PRIORITY
#define ETHERIF_STACKSIZE           512
#define ETHERIF_TIMESLICE           5

#define TCPIP_PRIORITY              DEFAULT_PRIORITY
#define TCPIP_STACKSIZE             1024
#define TCPIP_TIMESLICE             5

#define ETHERLINK_PRIORITY          (DEFAULT_PRIORITY+2)
#define ETHERLINK_STACKSIZE         1024
#define ETHERLINK_TIMESLICE         10

#define UDP_PRIORITY                DEFAULT_PRIORITY
#define UDP_STACKSIZE               1024
#define UDP_TIMESLICE               5


#define RYM_DOWN_TIMEOUT            (60*1000)

#define PIPE_VCP                    0
#define PIPE_BLE                    1
#define PIPE_485                    2
#define PIPE_NET                    3
#define PIPE_NONE                   0xFF

#define RS485_USART_HANDLE          &huart6

//#define DEBUG_APP


typedef union
{
    uint8_t byte;
    struct
    {
        uint8_t bit0:1;
        uint8_t bit1:1;
        uint8_t bit2:1;
        uint8_t bit3:1;
        uint8_t bit4:1;
        uint8_t bit5:1;
        uint8_t bit6:1;
        uint8_t bit7:1;
    }bits;
}byte_bit_t;

typedef struct
{
    GPIO_TypeDef* port;
    uint16_t pin;
}port_pin_t;


extern gqueue_t qYmRx,qYmTx;
/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
